package bid.web;

import bid.dao.ProfessorDao;
import bid.dao.impl.ProfessorDaoImpl;
import bid.entity.Professor;
import bid.util.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 * 专家的相关功能
 */
@WebServlet(value = "/professor")
public class ProfessorServlet extends HttpServlet {
    private ProfessorDao professorDao=new ProfessorDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //HttpSession session = req.getSession();
        int pageNo= StringUtils.toInt(req.getParameter("pageNo"),1);
        int pageSize=20;
        List<Professor> professors = professorDao.search(pageNo, pageSize);
        long l = professorDao.searchTotal();
        long pages=l/pageSize+(l%pageSize==0?0:1);
        req.setAttribute("pages",pages);
        req.setAttribute("pageNo",pageNo);
        //req称为上下文，可以带值去别的地方
        req.setAttribute("professors",professors);
        req.getRequestDispatcher("/prfessors.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
